@extends('../manage.layout')
@section('link')
    <link href="/plugin/select/select2.css" rel="stylesheet"/>
@stop
@section('content')
    <script>
        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="idea"]', {
                allowFileManager:false,
                width:"100%",
                height:'300px'
            });
        });
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            印刷供应商管理
            <small>编辑</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
            <li class="active">Here</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box-body table-responsive no-padding">
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">印刷供应商更新</h3>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        <form method="post" action="{{ url('manage/client/save') }}" role="form" enctype="multipart/form-data">
                            {{ csrf_field() }}
                            <input type="hidden" name="id" value="{{$clientInfo->id}}" />
                            {{--{{ method_field('PUT') }}--}}
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="title">公司名称</label>
                                    <input type="input" class="form-control" id="name" name="name" placeholder="公司名称" value="{{ $clientInfo->name }}" required>
                                </div>
                                <div class="form-group">
                                    <label for="name">联系人</label>
                                    <input type="input" class="form-control" id="linkman" name="linkman" placeholder="联系人" value="{{ $clientInfo->linkman }}">
                                </div>
                                <div class="form-group">
                                    <label for="name">联系方式</label>
                                    <input type="input" class="form-control" id="phone" name="phone" placeholder="联系方式" value="{{ $clientInfo->phone }}">
                                </div>
                                <div class="form-group">
                                    <label for="name">选择地点</label><br>
                                    <select name="province" id="loc_province" style="width:120px;"></select>
                                    <select name="city" id="loc_city" style="width:120px; margin-left: 10px"></select>
                                    <select name='county' id="loc_town" style="width:120px;margin-left: 10px"></select>
                                </div>
                                <div class="form-group">
                                    <label for="name">详细地址</label>
                                    <input class="form-control" rows="2" placeholder="地址" id="address" name="address" value="{{ $clientInfo->address }}"/>
                                </div>
                                <div class="form-group">
                                    <label for="name">权重</label>
                                    <input type="number" min="0" class="form-control" id="rank" name="rank" placeholder="0" value="{{ $clientInfo->rank }}">
                                </div>
                                <div class="form-group">
                                    <label for="name">经营范围</label>
                                    <textarea class="form-control" rows="2" placeholder="经营范围" id="scope" name="scope">{{ $clientInfo->scope }}</textarea>
                                </div>
                                <div class="form-group">
                                    <label for="name">备注</label>
                                    <textarea class="form-control" rows="2" placeholder="备注" id="remark" name="remark">{{ $clientInfo->remark }}</textarea>
                                </div>
                            <!-- /.box-body -->
                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">确定</button>&nbsp;&nbsp;<span class="btn btn-primary" onclick="window.location.href='/manage/client'">返回</span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
@endsection
@section('script')
    <script>
        //提交表单z'c
        $("form").submit(function(event) {
            event.preventDefault();
            var url = $(this).attr("action");
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            var data = $("form").serialize()+'&province='+$('#loc_province').select2('data').text+'&city='+$('#loc_city').select2('data').text+'&county='+$('#loc_town').select2('data').text
            console.log(data);
            $.ajax({
                url: url,
                type: "POST",
                data: data,
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    if(data.error == 0) {
//                        window.location.href = window.location.href;
                        layer.msg(data.msg)
                    }
                    else {
                        layer.msg(data.msg)
                    }
                },
                error:function(){
                    alert('ERROR');
                }
            });
        });

    </script>
    <script type="text/javascript" src="/plugin/select/jquery.js"></script>
    <script type="text/javascript" src="/plugin/select/area.js"></script>
    <script type="text/javascript" src="/plugin/select/location.js"></script>
    <script src="/plugin/select/select2.js"></script>
    <script src="/plugin/select/select2_locale_zh-CN.js"></script>
    <script>
        $(function(){
            {{--alert('{{$clientInfo['province']}}');--}}
            showLocation('','','','{{$clientInfo['province']}}','{{$clientInfo['city']}}','{{$clientInfo['county']}}');
        });
    </script>
@endsection
